<template>
    <van-skeleton v-if="status" title :row="3" />
    <div v-else>
        <van-nav-bar title="商品分类" left-text="返回" left-arrow @click-left="() => { $router.push('/home/index') }" />
        <van-row>
            <van-col span="6">
                <van-sidebar v-model="active">
                    <van-sidebar-item v-for="item in categories" :title="item.cat_name" />
                </van-sidebar>
            </van-col>
            <van-col span="18">

                <van-search v-model="value" show-action label="地址" placeholder="请输入搜索关键词"
                    @search="onSearch"></van-search>
             

                <div v-for="item in categories[active]?.children">
                    <h4>{{ item.cat_name }}</h4>
                    <router-link :to="'/lie/' + item.cat_name">
                        <van-grid :column-num="4">

                            <van-grid-item v-for="items in item.children" :icon="items.cat_icon"
                                :text="items.cat_name" />

                        </van-grid>
                    </router-link>
                </div>

            </van-col>
        </van-row>
    </div>
</template>

<script setup>
import { ref,watch } from 'vue';
import { categoriesApi } from '@/api/api'
let status = ref(true)
setTimeout(() => {
    status.value = false
}, 2000)
let categories = ref([])
categoriesApi().then(res => {
    console.log('商品分类', res);
    categories.value = res.data.message
})
let active = ref(1)

import { useRouter } from 'vue-router';
let router=useRouter()
const onSearch=()=>{
    router.push('/ss')
}
</script>

<style lang="scss" scoped></style>